<template>
	<view>
		<view class="fixAuto whiteBg ptb15" :class="{'middle':!showAll}">
			<view class="w80">
				<view class="square" :class="isRound?'rds100 shadow':'rds4'">
					<image :src="info[picKey]" v-if="info[picKey]" class=" bd" :class="isRound?'rds100':'rds4'" mode="aspectFill"></image>
					<image src="../../static/defaultPhoto.jpg" v-else class="bd" :class="isRound?'rds100':'rds4'" mode="aspectFill"></image>
				</view>
			</view>
			<view>
				<view class="fz16">
					{{info[nameKey]}} 
					<view class="tag ml10" style="position: relative;top: -2px;" v-if="info.roleName">
						{{info.roleName}}
					</view>
				</view>
				<view class="gray fz14 " :class="{'clip c2':!showAll}" v-if="info[introKey]">
					{{info[introKey]}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'userInfo',
		data() {
			return {
				
			};
		},
		props: {
			info: {
				default : function(e){
					return {};
				}
			},
			value : {
				default : ""
			},
			disabled : {
				default : false 
			},
			showAll : {
				default : false 
			},
			isRound : {
				default : false 
			},
			nameKey : {
				default : "realName"
			},
			picKey : {
				default : "headImgUrl"
			},
			introKey : {
				default : "intro"
			}
		},
		
		computed:{
			countSync:function(e){
				return Number(this.count);
			},
		},
		
		watch:{
			value : function(){
				if (!this.value) {
					return ;
				}
				this.list = typeof this.value == 'object' ? this.value : this.value.split(",") ;
			},
		},
		
		methods: {
			toUploadImage:function(key){
				var sourceTypes = ["album", "camera"];
				uni.showActionSheet({
					itemList:["从相册选择","从相机拍照"],
					success : res => {
						uni.chooseImage({
							sourceType:[sourceTypes[res.tapIndex]],
							count: this.countSync ,
							success: res =>{
								uni.showNavigationBarLoading();
								var arr = res.tempFilePaths ;
								var nowLength = this.list.length ;
								for (var i = 0; i < arr.length; i++) {
									var path = arr[i] ;
									this.qiniu.upload(path , res =>{
										if (this.list.length <= this.countSync) {
											this.list.push(res);
											this.change();
										}
										if (this.list.length - nowLength == arr.length) {
											uni.hideNavigationBarLoading();
										}
									});
								}
							}
						});
					}
				});
			},
			
			preview:function(e){
				uni.previewImage({
					urls:this.list ,
					current: e 
				});
			},
			
			deleteImage:function(index){
				this.list.splice(index,1);
				this.change();
			},
			
			change:function(e){
				this.$emit('change' , { list : this.list , value : this.list.join(",") });
			},
		}
	}
</script>

<style>

</style>
